﻿exports.DateUtils = {
    
    /**
	* 字符串转时间（yyyy-MM-dd HH:mm:ss）
	* 
	*/
	stringToDate : function (sDate) {
    var fullDate = sDate.split(" ")[0].split("-");
    var fullTime = sDate.split(" ")[1].split(":");
        
    return new Date(fullDate[0], fullDate[1] - 1, fullDate[2], (fullTime[0] != null ? fullTime[0] : 0), (fullTime[1] != null ? fullTime[1] : 0), (fullTime[2] != null ? fullTime[2] : 0));
    },
    
    /**
	* 时间转字符串（yyyy-MM-dd HH:mm:ss）
	* 
	*/
    dateToString : function (dDate,format) {
        var year = dDate.getYear() + 1900;
        var month = dDate.getMonth() + 1;//month
        var date = dDate.getDate();//day
        var hour = dDate.getHours(); //hour
        var minute = dDate.getMinutes(); //minute
        var second = dDate.getSeconds(); //second
        var quarter = Math.floor((dDate.getMonth() + 3) / 3); //quarter
        var millisecond = dDate.getMilliseconds(); //millisecond
        if (format) {
            if (format == "yyyy-MM-dd") {
                return year + '-' + month + '-' + date;
            } else {
                return year + '-' + month + '-' + date + ' ' + hour + ':' + minute + ':' + second;
            }
        } else {
            return year + '-' + month + '-' + date + ' ' + hour + ':' + minute + ':' + second;
        }
    }
    
};